﻿// -----------------------------------------------------------------------
// <copyright file="ScalarRetrievalTaskHelper.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Dhgms.TplHelper.Model.TaskHelper
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using Dhgms.TplHelper.Controller.Task;
    using Dhgms.TplHelper.Model.DataReaderConsumer;
    using Dhgms.TplHelper.Model.DataReaderProducer;
    using Dhgms.TplHelper.Model.Info;
    using Dhgms.TplHelper.Model.Info.JobResult;
    using Dhgms.TplHelper.Model.Info.TaskResult;


    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public abstract class DataRetrievalTaskHelper<TDataReaderProducer, TDataReaderConsumer, TTaskResultClass, TTaskDataType> : InternalTransformerTaskHelper<TTaskResultClass, TTaskDataType>
        where TDataReaderProducer : IDataReaderProducer
        where TDataReaderConsumer : IDataReaderConsumer, ITaskDataResult<TTaskDataType>
        where TTaskResultClass : TaskResultBase, IReportableCount, ITaskDataResult<TTaskDataType>, new()
    {
        protected DataRetrievalTaskHelper(string name)
            : base(name)
        {
        }

        /// <summary>
        /// Gets the producer.
        /// </summary>
        /// <returns>The producer</returns>
        protected abstract TDataReaderProducer GetProducer();

        /// <summary>
        /// Gets the consumer.
        /// </summary>
        /// <returns>The consumer</returns>
        protected abstract TDataReaderConsumer GetConsumer();

        protected override DataRetrievalProcessorResult<TTaskDataType> OnProcess()
        {
            var producer = GetProducer();
            var consumer = GetConsumer();

            var executionResult = producer.ProduceAndConsume(consumer.DataReaderAction);

            var result = new DataRetrievalProcessorResult<TTaskDataType>(executionResult, consumer.Data);
            return result;
        }
    }
}
